# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=tools

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
replaces="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_ver_base=4.0.0
pkgver=4.0.0.4044.502c720
pkgrel=1
pkgdesc="MinGW-w64 tools"
arch=('any')
url="http://mingw-w64.sourceforge.net"
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain" "${MINGW_PACKAGE_PREFIX}")
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-libmangle")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs' '!emptydirs')
source=("${_realname}"::"git://git.code.sf.net/p/mingw-w64/mingw-w64")
md5sums=('SKIP')
_tools="gendef genidl genpeimg widl"

pkgver() {
  cd "$srcdir/${_realname}"
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  local cur=
  for cur in ${_tools}; do
    plain "Building ${cur} ..."
    mkdir -p ${srcdir}/${MINGW_CHOST}-${cur}
    cd ${srcdir}/${MINGW_CHOST}-${cur}
    ${srcdir}/${_realname}/mingw-w64-tools/${cur}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --with-mangle=${MINGW_PREFIX}
    make
  done
}

package() {
  local cur=
  for cur in ${_tools}; do
    plain "Installing ${cur} ..."
    cd ${srcdir}/${MINGW_CHOST}-${cur}
    make DESTDIR=${pkgdir} install
    if [[ -f "${srcdir}/${_realname}/mingw-w64-tools//${cur}"/COPYING ]]; then
      install -Dm644 ${srcdir}/${_realname}/mingw-w64-tools/${cur}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/mingw-w64-tools/COPYING.${cur}
    fi
  done
}
